<?php

class Jd_config_model extends MY_Model {

    public function __construct()
    {
        $this->modelename='Jd_config_model';
        $this->tablename='config';
        parent::__construct();
    }


    public function gettable($wangwang=0){
        return $this->tablename;
    }


    /**
     * 添加信息进入数据库
     * @param $row
     * @return INT
     */
    public function addinfo($row){

        return $this->add($this->gettable(),$row);
    }


    /**
     *  通过配置名获取配置信息
     */
    public function GetByname($name,$select="value",$webid=""){
        $sql="select $select from jd_config where `name`='$name'  AND (webid=$this->web_id or webid=1) order  by webid desc limit 1";
        if($webid){
            $sql="select $select from jd_config where `name`='$name'  AND webid=$webid order  by webid desc limit 1";
        }

        return $this->GetBySql($sql,0);
    }

    /**
     * 获取列表
     */
    public function getlist($page,$epage){
        $sql="select * from  jd_config where 1=1 ";
        $sql.= " limit ".($epage* ($page - 1)).", $epage";
        return $this->GetBySql($sql);
    }

    public function  updateinfo($id,$value){
        $sql="update jd_config set `value`='$value' where id= ".$id;
        return $this->db->query($sql);
    }

    public function  updateinfobyname($name,$value){
        $sql="update jd_config set `value`='$value' where `name`=  '$name' AND webid=$this->web_id";
        return $this->db->query($sql);
    }














}
